package cn.com.wind.bdg.collect.collect;

import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import cn.com.wind.bdg.collect.collect.service.KafkaService;
import cn.com.wind.bdg.collect.collect.service.UrlContent2HbaseService;
import cn.com.wind.bdg.collect.collect.utils.GetHtml;

@SpringBootApplication
public class CollectApplication implements ApplicationRunner{

	public static void main(String[] args) {
		SpringApplication.run(CollectApplication.class, args);
	}

	@Autowired
    private UrlContent2HbaseService urlContent2HbaseService;
	@Autowired
	private KafkaService kafkaService;
	/**
	 * 重写run方法，执行相关业务操作
	 */
	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		List<String> list = GetHtml.method();
		int i=1;
		for(String url:list){
			Document document = Jsoup.connect(url).get();
	    	String doc = new String(document.toString());
	    	//原始文件发送kafka
	    	kafkaService.init();
	    	kafkaService.produce("content", doc);
	    	//原始文件归档HBase
	    	urlContent2HbaseService.deal(doc,i);
	    	i++;
	    	
		}
	}

}
